package cn.south.campus.admin.sys.controller;

import cn.south.campus.admin.sys.model.req.SysRoleReq;
import cn.south.campus.admin.sys.model.vo.SysRoleVo;
import cn.south.campus.admin.sys.service.SysRoleService;
import cn.south.campus.common.model.bo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/10/31 13:24
 */
@RestController
@RequestMapping("admin/role")
@AllArgsConstructor
public class SysRoleController {

    private final SysRoleService sysRoleService;

    @PostMapping("/add")
    public Result<String> add(@RequestBody SysRoleVo vo) {
        sysRoleService.add(vo);
        return Result.success("新增成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result<String> delete(@PathVariable Long id) {
        sysRoleService.delete(id);
        return Result.success("删除成功");
    }

    @PutMapping("/update")
    public Result<String> update(@RequestBody SysRoleVo vo) {
        sysRoleService.updateRole(vo);
        return Result.success("更新成功");
    }

    @GetMapping("/detail/{id}")
    public Result<SysRoleVo> detail(@PathVariable Long id) {
        return Result.success(sysRoleService.detail(id));
    }

    @GetMapping("/page")
    public Result<IPage<SysRoleVo>> pageRole(SysRoleReq req) {
        return Result.success(sysRoleService.page(req));
    }

    @GetMapping("/list")
    public Result<List<SysRoleVo>> list() {
        return Result.success(sysRoleService.getList());
    }


}
